#!/usr/bin/python3

from datetime import datetime, timedelta

import pytz


#
# 这个函数用于计算从当前时间算起的超时时间
#
# calc_expire(seconds=20)   <-- 表示20秒后超时
# calc_expire(days=3)       <-- 表示3天后超时
#
def calc_expire(tz='Asia/Chongqing', **kargs):
    now = datetime.now()
    tz = pytz.timezone(tz)          # 创建时区
    now = tz.localize(now)          # 给时间加上时区信息
    delta = timedelta(**kargs)
    now = now + delta
    return now.strftime('%a, %d %b %Y %H:%M:%S %z')


expire = calc_expire(seconds=20)

print('Content-Type: text/plain')
print('Set-Cookie: age=18; expires=%s' % expire)
print()
print('hello cookie.')
